<template>
    <Pop :show="account.popSubscribe" title="订阅提示" @close="onClose">
        <div class="tip1">订阅资讯消息需要消耗{{ user.curSubs.energy }}能量</div>
        <div class="tip2">订阅成功后，重大资讯消息将会发送到您邮箱</div>

        <div class="btns">
            <v-btn class="btn-1 submit-btn" color="#787570" type="submit" @click="onClose"> 取消订阅 </v-btn>
            <v-btn class="btn-2 submit-btn" color="primary" type="submit" @click="onSure"> 确认订阅 </v-btn>
        </div>
    </Pop>
</template>

<script lang="ts" setup>
import Pop from "@/components/pop/index.vue";
import { toast } from "@/components/toast/toast";
import { useAccount } from "@/stores/account";
import { useUser } from "@/stores/user";

const account = useAccount();
const user = useUser();

const onClose = () => {
    account.changePopSubscribe(false);
};
const onSure = async () => {
    if (user.info.energy < user.curSubs.energy) {
        toast("能量值不足");
        onClose();
        return;
    }
    let res = await user.addSubscriber({
        id: user.curSubs.id,
        days: user.curSubs.days
    });
    if (res) {
        toast(res);
    } else {
        toast("訂閲成功");
        onClose();
    }
};
</script>

<style lang="less" scoped>
.tip1 {
    font-size: 18px;
    color: #fff;
    margin-bottom: 10px;
}
.tip2 {
    font-size: 18px;
    color: #fff;
    margin-bottom: 80px;
}
.btns {
    display: flex;
    justify-content: center;
    align-items: center;
    .btn-1 {
        width: 160px;
        height: 42px;
        margin-right: 22px;
    }
    .btn-2 {
        width: 160px;
        height: 42px;
    }
    :deep(.v-btn__content) {
        color: #333;
    }
}
</style>
